#!/usr/bin/env python
#-*- coding:utf-8 -*-

from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String
from sqlalchemy import ForeignKey

engine = create_engine('sqlite:///saplatform.db', echo=True)
Base = declarative_base()

class Server(Base):
    __tablename__ = 'saplatform_server'

    sid          = Column(String, primary_key = True)
    name         = Column(String)
    location     = Column(String)
    eth0_ip      = Column(String)
    eth1_ip      = Column(String)
    rcc_ip       = Column(String)
    machine_info = Column(String)
    cpu_info     = Column(String)
    mem_info     = Column(String)
    hd_info      = Column(String)
    os_info      = Column(String)
    kernel_info  = Column(String)
    desc         = Column(String)


    def __init__(self, sid,
                 name = '',
                 location = '',
                 eth0_ip = '',
                 eth1_ip = '',
                 rcc_ip = '',
                 machine_info = '',
                 cpu_info = '',
                 mem_info = '',
                 hd_info = '',
                 os_info = '',
                 kernel_info = '',
                 desc = ''):
        self.sid          = sid
        self.name         = name
        self.location     = location
        self.eth0_ip      = eth0_ip
        self.eth1_ip      = eth1_ip
        self.rcc_ip       = rcc_ip
        self.machine_info = machine_info
        self.cpu_info     = cpu_info
        self.mem_info     = mem_info
        self.hd_info      = hd_info
        self.os_info      = os_info
        self.kernel_info  = kernel_info
        self.desc         = desc

class Localservice(Base):
    __tablename__ = "saplatform_localservice"

    sid = Column(String, ForeignKey("saplatform_server.sid"), primary_key=True)
    port = Column(String, primary_key=True)
    servicename = Column(String)

    def __init__(self, sid, port, servicename):
        self.sid = sid
        self.port = port
        self.servicename = servicename
